/**
 ** @author:		周羽
 ** @date:			2017-03-30
 ** @brief:			数据库的插入
 */

#include "pthread_sqlite.h"

extern struct env_info b;

//向数据库中插入数据
void sqlite_insert(void)
{
	if(SQLITE_OK != sqlite3_open("./warehouse.db", &db))
	{
		printf("warehouse.db open error\n");
		exit(-1);
	}

	char cmd[256] = {0};
	printf("%d\n", b.temp[0]);
	sprintf(cmd, "insert into warehouse_env values (%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f);",//此处使用了强制类型转换
			(float)(b.temp[0]), (float)(b.temp[1]), (float)(b.hum[0]), (float)(b.hum[1]), (float)(b.x), (float)(b.y), (float)(b.z), (float)(b.ill), (float)(b.bet), (float)(b.adc));

	if(SQLITE_OK != sqlite3_exec(db, cmd, NULL, NULL, &errmsg))
	{
		printf("%s\n", sqlite3_errmsg(db));
		exit(-1);
	}
}
